package com.hc.dfs.service.common;

import java.util.HashMap;
import java.util.Map;

public class Page implements java.io.Serializable{

	private static final long serialVersionUID = 190026372251380292L;

	public Page(){

	}
	public Page(int pageSize ,int pageNum){

		this.pageSize = pageSize;
		this.page = pageNum;
	}

	private int pageSize = 10;
	private int page;
	private int total;
	private Map<String, Object> params = new HashMap<String, Object>();

	private int navNum =8;
	
	/**
	 * 获取总页数
	 * @return
	 */
	
	public int getTotalPage() {
		int rs =(total % pageSize) >0 ? (total / pageSize) +1 :(total / pageSize);
		return rs==0?1:rs;
	}
	/**
	 * 获取导航条
	 * @return
	 */
	public int[] getNavBar() {
		int qn =navNum / 2;
		int tpage = getTotalPage();
		int page = getPage();
		if(page >navNum-1&&tpage!=navNum){
			int ps =page -qn;
			int pe = page + qn;
			int[] na= new int[navNum+1];
			
			if(pe >= tpage){
				for (int i = 0; i < na.length; i++) {
					na[i] = ((tpage-navNum)+i);
				}
				return na;
			}else{
				int j =0;
				for (int i = ps; i <= pe; i++) {
					na[j]= i;
					j++;
					if(j >na.length) break;
				}
				return na;
			}
		}else{
			int[] na= new int[navNum-tpage >0?tpage:navNum];
			for (int i = 0; i < na.length; i++) {
				na[i] = (i+1);
			}
			return na;
		}
	}
	
	
	
	
	/**
	 * @return the pageSize
	 */
	public int getPageSize() {
		return pageSize;
	}
	/**
	 * @param pageSize the pageSize to set
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	/**
	 * @return the pageNum
	 */
	public int getPage() {
		int t = getTotalPage();
		if(page ==0) page = 1;
		else if(page > t) page=t;
		
		return page;
	}
	/**
	 * @param pageNum the pageNum to set
	 */
	public void setPage(int page) {
		this.page = page;
	}
	/**
	 * @return the startNum
	 */
	public int getStartNum() {

		return (getPage() -1) * pageSize;

	}
	/**
	 * @return the endNum
	 */
	public int getEndNum() {
		return  getPageSize();
	}
	/**
	 * @return the params
	 */
	public Map<String, Object> getParams() {
		return params;
	}
	/**
	 * @param params the params to set
	 */
	public void setParams(Map<String, Object> params) {
		this.params = params;
	}
	/**
	 * @return the total
	 */
	public int getTotal() {
		return total;
	}
	/**
	 * @param total the total to set
	 */
	public void setTotal(int total) {
		this.total = total;
	}
	

}
